/**
 * 
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springmodules.cache.annotations.Cacheable;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.CfgRequestDefnToProDiagIgnore;

/**
 * @author 212042764
 * 
 */
public class RequestDefn2ProDiagsBlockDAO extends BaseDAO implements
		IRequestDefn2ProdiagBlockDAO {

	/**
	 * Eclipse Generated
	 */
	private static final long serialVersionUID = 3112498429341157129L;
	public static final String TABLE_NAME = "com.ge.healthcare.autosc.common.database.pojo.CfgRequestDefnToProDiagIgnore";
	public static final String REQUEST_DEFN_ID = "id.requestDefnId";
	public static final String ISO_CODE_ID = "id.isoCode";
	public static final String ALL_COUNTRIES = "*";

	public RequestDefn2ProDiagsBlockDAO() {
		super(TABLE_NAME);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.ISweepPropertiesDAO#getSweepPropForRequestDefn(java.lang.Long)
	 */
	@Cacheable(modelId = "RequestDefn2ProdiagBlockDAOCacheModel")
	public List<String> getProDiagBlockLstForRequestDefn(Long requestDefnId,
			String isoCode) {
		if (ASCUtil.isNullOrEmptyObject(requestDefnId)) {
			return null;
		}
		Map<String, Object> findMap = new HashMap<String, Object>();
		findMap.put(REQUEST_DEFN_ID, requestDefnId);
		findMap.put(ISO_CODE_ID, isoCode);
		List<?> rtvdProDiagsBlock = this.findByProperties(findMap);
		if (ASCUtil.isNullOrEmptyList(rtvdProDiagsBlock)) {
			if (ALL_COUNTRIES.equalsIgnoreCase(isoCode)) {
				return null;
			} else {
				return getProDiagBlockLstForRequestDefn(requestDefnId,
						ALL_COUNTRIES);
			}
		}
		List<String> filePatterns = new ArrayList<String>();
		for (int iCount = 0; iCount < rtvdProDiagsBlock.size(); iCount++) {
			String filePattern = ((CfgRequestDefnToProDiagIgnore) rtvdProDiagsBlock
					.get(iCount)).getId().getCfgProdiagBlockList()
					.getFilePattern();
			filePatterns.add(filePattern.trim());
		}
		return filePatterns;
	}

	public void saveAlways(Object pojo) {
		this.save(pojo);
	}

}
